package com.wing.cabinet.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.cabinet.dao.StorageSingleInventoryProductDao;
import com.wing.cabinet.model.entity.StorageSingleInventoryProduct;
import com.wing.cabinet.model.request.StorageSingleInventoryProductForm;
import com.wing.cabinet.model.response.KnifeCabinetProductExportVO;
import com.wing.cabinet.model.response.SingleInventoryProductExportVO;
import com.wing.cabinet.model.response.StorageSingleInventoryProductVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 暂存柜产品库存(单个柜子)-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class StorageSingleInventoryProductServiceImpl extends ServiceImpl<StorageSingleInventoryProductDao, StorageSingleInventoryProduct> implements StorageSingleInventoryProductService {

    @Override
    public int add(StorageSingleInventoryProductForm storageSingleInventoryProductForm) {

        //校验

        StorageSingleInventoryProduct storageSingleInventoryProduct =new StorageSingleInventoryProduct();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(StorageSingleInventoryProduct.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(storageSingleInventoryProductForm, storageSingleInventoryProduct, copyOptions);

        return baseMapper.insert(storageSingleInventoryProduct);
    }

    @Override
    public List<StorageSingleInventoryProductVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<StorageSingleInventoryProductVO> pageList4app(Page page, Map<String, Object> params) {
        List<StorageSingleInventoryProductVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public Page<StorageSingleInventoryProductVO> pageList(Page page, Map<String, Object> params) {
            List<StorageSingleInventoryProductVO> list = baseMapper.list(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public StorageSingleInventoryProductVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    @Override
    public List<StorageSingleInventoryProductVO> ecxportList(Map<String, Object> params) {
        List<StorageSingleInventoryProductVO> list = baseMapper.list4app(params);
        /*try {
            for (int i=0;i<list.size();i++) {
                String skuPic = list.get(i).getSkuPic();

                if (StringUtils.isNotEmpty(skuPic)){
                    URL pic = new URL(skuPic);
                    list.get(i).setSkuPicVo(pic);
                }
            }
        } catch (MalformedURLException e) {
            System.out.println("在库统计URL转换失败："+e.getMessage());
        }*/
        return list;
    }

    @Override
    public Page<StorageSingleInventoryProductVO> pageListStorageInventoryCabinet(Page page, Map<String, Object> params) {
        List<StorageSingleInventoryProductVO> list = baseMapper.pageListStorageInventoryCabinet(page, params);
        page.setRecords(list);
        return page;
    }
    @Override
    public Page<StorageSingleInventoryProductVO> getStorageSingleBySkuCodeAndBelongCabinet(Page page, Map<String, Object> params) {
        List<StorageSingleInventoryProductVO> list = baseMapper.getStorageSingleBySkuCodeAndBelongCabinet(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public List<SingleInventoryProductExportVO> inventoryProductExportList(Map<String, Object> params) {
        return baseMapper.inventoryProductExportList(params);
    }
    @Override
    public List<KnifeCabinetProductExportVO> knifeCabinetProductExportVoEcxportList(Map<String, Object> params) {
        return baseMapper.knifeCabinetProductExportVoEcxportList(params);
    }

    @Override
    public Page<StorageSingleInventoryProductVO> getAllStorageSingleBySkuCodeAndBelongCabinet(Page page, Map<String, Object> params) {
        List<StorageSingleInventoryProductVO> list = baseMapper.getAllStorageSingleBySkuCodeAndBelongCabinet(page, params);
        page.setRecords(list);
        return page;
    }

}
